<%@ page language="java" import="java.util.*,com.knife.member.*,com.knife.member.stat.*,tools.MD5" pageEncoding="UTF-8"%>
<%
Userinfo auser=null;
Boolean isLogin=false;
String login_email="";
String login_pass="";
UserinfoDAO userDAO = new UserinfoDAO();
/*if(session.getAttribute("uname")!=null){
	login_email=session.getAttribute("uname").toString();
}*/
Cookie[] cookies=request.getCookies();
if(cookies!=null){
	for(int i=0;i<cookies.length;i++){
		String sp = cookies[i].getName();
		if(sp.equals("loginuser")){
			login_email=cookies[i].getValue();
	    }else if(sp.equals("loginpass")){
			login_pass=cookies[i].getValue();
	    }
    }
}
if(login_email.length()>0){
	List<Userinfo> users = new ArrayList<Userinfo>();
	try{
		users = userDAO.findActiveByEmail(login_email);
	}catch(Exception e){
	}
	if(users.size()>0){
		auser=users.get(0);
		//if(cipher.validatePassword(auser.getPassword(), pwd1)){
		if(login_pass.equals(MD5.getMD5(auser.getPassword().getBytes()))){
			String acount="";
			if(session.getAttribute("loginuser")!=null){
				acount=session.getAttribute("loginuser").toString();
			}
			if(acount.equals(auser.getEmail())){
				isLogin=true;
			}
		}
	}
}
//结束上一篇文档
if(session.getAttribute("viewedid")!=null){
	int vieweid=Integer.parseInt(session.getAttribute("viewedid").toString());
	if(vieweid>0){
		StatHandle.insertEndTime(vieweid);
	}
}
if(!isLogin){
	response.sendRedirect("/user/login.jsp");
}
%>